<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>产品检验</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<link rel="stylesheet" href="${pageContext.request.contextPath }/assets/css/layui.css"  media="all">
	<link rel="stylesheet" href="${pageContext.request.contextPath }/assets/css/toastr.min.css"  media="all">
	<link rel="stylesheet" href="${pageContext.request.contextPath}/assets/ztree/css/zTreeStyle/zTreeStyle.css">
	
	<script type="text/javascript" src="${pageContext.request.contextPath }/assets/js/jquery.min.js" charset="utf-8"></script>
	<script type="text/javascript" src="${pageContext.request.contextPath}/assets/ztree/js/jquery.ztree.all.min.js"></script>
	<script type="text/javascript" src="${pageContext.request.contextPath}/assets/ztree/js/jquery.ztree.core.js"></script>  
    <script type="text/javascript" src="${pageContext.request.contextPath}/assets/ztree/js/jquery.ztree.excheck.js"></script>  
    <script type="text/javascript" src="${pageContext.request.contextPath}/assets/ztree/js/jquery.ztree.exedit.js"></script>
	<style type="text/css">
	</style>
</head>
<body>
<!-- 上表 -->
<script type="text/html" id="toolbarDemo">
	<div class="layui-btn-container">
		<button class="layui-btn layui-btn-blue" lay-event="add"><i class="layui-icon layui-icon-add-1">  新增</i></button>
		<button class="layui-btn layui-btn-blue" lay-event="delete"><i class="layui-icon layui-icon-delete">  批量删除</i></button>
	</div>
</script>
<h2 style="text-align: center;color:#666">产品检验单</h2>
<table class="layui-hide" id="inspectionSheet" lay-filter="inspectionSheet"></table>
<script type="text/html" id="barDemo">
	<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<!-- 下表 -->
<h2 style="text-align: center;color:#666" class="layui-hide" id="detailsTitle">检验单详情</h2>
<table class="layui-hide" id="inspectionSheetDetails" lay-filter="inspectionSheetDetails"></table>
<form class="layui-form layui-card-body" id="content" hidden>
	<input class="layui-input" style="width:300px;display: inline-block;" placeholder="请输入排产单号" id="remark02" oninput="onInput()"/>
	<div class="layui-input-inline" style="width:300px">
		<select id="remark03" lay-filter="remark03">
			<option value="-1">请选择检验结果</option>
		</select>
	</div>
	<table class="layui-table" id="tab">
		<thead>
			<tr>
				<th>检验项目</th>
				<th>检验指标</th>
				<th>标准值</th>
				<th>合格值</th>
				<th>异常值</th>
				<th>检测值</th>
				<th>指标检验数量</th>
				<th>指标合格数量</th>
				<th>指标质量判定</th>
			</tr>
		</thead>
		<tbody>
			<tr>
				<td><input class="layui-input" readonly value="组件产水通量" name="isItem"/></td>
				<td><input class="layui-input" readonly value="组件产水通量"/></td>
				<td><input class="layui-input" readonly value="" name=""/></td>
				<td><input class="layui-input" readonly value="${zcEvaluateCriterionEntity.csFluxOne }" name=""/></td>
				<td><input class="layui-input" readonly value="${zcEvaluateCriterionEntity.csFluxTwo }" name=""/></td>
				<td><input class="layui-input" readonly value="" name="isValue" id="cstl"/></td>
				<td><input class="layui-input" readonly value="" name="isCheckNum"/></td>
				<td><input class="layui-input" value="" name="isBetterNum"/></td>
				<td>
					<div class="layui-input-block" style="width: 100%;margin-left: auto">
						<select name="isDecide" class="layui-select">
							<option value="合格">合格</option>
							<option value="不合格">不合格</option>
						</select>
					</div>
				</td>
			</tr>
			<tr>
				<td><input class="layui-input" readonly value="组件软硬胶总数" name="isItem"/></td>
				<td><input class="layui-input" readonly value="组件软硬胶总数"/></td>
				<td><input class="layui-input" readonly value="" name=""/></td>
				<td><input class="layui-input" readonly value="${zcLeakHuntingCriterionEntity.ryCountOne }" name=""/></td>
				<td><input class="layui-input" readonly value="${zcLeakHuntingCriterionEntity.ryCountTwo }" name=""/></td>
				<td><input class="layui-input" readonly value="" name="isValue" id="ryjNumCount"/></td>
				<td><input class="layui-input" readonly value="" name="isCheckNum"/></td>
				<td><input class="layui-input" value="" name="isBetterNum"/></td>
				<td>
					<div class="layui-input-block" style="width: 100%;margin-left: auto">
						<select name="isDecide" class="layui-select">
							<option value="合格">合格</option>
							<option value="不合格">不合格</option>
						</select>
					</div>
				</td>
			</tr>
			<tr>
				<td><input class="layui-input" readonly value="组件瘪丝数" name="isItem"/></td>
				<td><input class="layui-input" readonly value="组件瘪丝数"/></td>
				<td><input class="layui-input" readonly value="" name=""/></td>
				<td><input class="layui-input" readonly value="${zcLeakHuntingCriterionEntity.bsCountOne }" name=""/></td>
				<td><input class="layui-input" readonly value="${zcLeakHuntingCriterionEntity.bsCountTwo }" name=""/></td>
				<td><input class="layui-input" readonly value="" name="isValue" id="bsNum"/></td>
				<td><input class="layui-input" readonly value="" name="isCheckNum"/></td>
				<td><input class="layui-input" value="" name="isBetterNum"/></td>
				<td>
					<div class="layui-input-block" style="width: 100%;margin-left: auto">
						<select name="isDecide" class="layui-select">
							<option value="合格">合格</option>
							<option value="不合格">不合格</option>
						</select>
					</div>
				</td>
			</tr>
			<tr>
				<td><input class="layui-input" readonly value="组件弯曲、压丝数" name="isItem"/></td>
				<td><input class="layui-input" readonly value="组件弯曲、压丝数"/></td>
				<td><input class="layui-input" readonly value="" name=""/></td>
				<td><input class="layui-input" readonly value="${zcLeakHuntingCriterionEntity.wsCountOne }" name=""/></td>
				<td><input class="layui-input" readonly value="${zcLeakHuntingCriterionEntity.wsCountTwo }" name=""/></td>
				<td><input class="layui-input" readonly value="" name="isValue" id="wqysNum"/></td>
				<td><input class="layui-input" readonly value="" name="isCheckNum"/></td>
				<td><input class="layui-input" value="" name="isBetterNum"/></td>
				<td>
					<div class="layui-input-block" style="width: 100%;margin-left: auto">
						<select name="isDecide" class="layui-select">
							<option value="合格">合格</option>
							<option value="不合格">不合格</option>
						</select>
					</div>
				</td>
			</tr>
			<tr>
				<td><input class="layui-input" readonly value="非边缘端面补胶" name="isItem"/></td>
				<td><input class="layui-input" readonly value="非边缘端面补胶"/></td>
				<td><input class="layui-input" readonly value="" name=""/></td>
				<td><input class="layui-input" readonly value="${zcLeakHuntingCriterionEntity.dmbjOne }" name=""/></td>
				<td><input class="layui-input" readonly value="${zcLeakHuntingCriterionEntity.dmbjTwo }" name=""/></td>
				<td><input class="layui-input" readonly value="" name="isValue" id="dmbj"/></td>
				<td><input class="layui-input" readonly value="" name="isCheckNum"/></td>
				<td><input class="layui-input" value="" name="isBetterNum"/></td>
				<td>
					<div class="layui-input-block" style="width: 100%;margin-left: auto">
						<select name="isDecide" class="layui-select">
							<option value="合格">合格</option>
							<option value="不合格">不合格</option>
						</select>
					</div>
				</td>
			</tr>
			<tr>
				<td><input class="layui-input" readonly value="检漏总数" name="isItem"/></td>
				<td><input class="layui-input" readonly value="检漏总数"/></td>
				<td><input class="layui-input" readonly value="${zcLeakHuntingCriterionEntity.nleakHuntingCountOne }" name=""/></td>
				<td><input class="layui-input" readonly value="${zcLeakHuntingCriterionEntity.nleakHuntingCountTwo }" name=""/></td>
				<td><input class="layui-input" readonly value="" name=""/></td>
				<td><input class="layui-input" readonly value="" name="isValue" id="nleakHuntingCount"/></td>
				<td><input class="layui-input" readonly value="" name="isCheckNum"/></td>
				<td><input class="layui-input" value="" name="isBetterNum"/></td>
				<td>
					<div class="layui-input-block" style="width: 100%;margin-left: auto">
						<select name="isDecide" class="layui-select">
							<option value="合格">合格</option>
							<option value="不合格">不合格</option>
						</select>
					</div>
				</td>
			</tr>
			<tr>
				<td><input class="layui-input" readonly value="组件气密性" name="isItem"/></td>
				<td><input class="layui-input" readonly value="组件气密性"/></td>
				<td><input class="layui-input" readonly value="一次间隔${zcGasCriterionEntity.oneTime }s、三次间隔${zcGasCriterionEntity.threeTime }s" name=""/></td>
				<td><input class="layui-input" readonly value="" name=""/></td>
				<td><input class="layui-input" readonly value="" name=""/></td>
				<td><input class="layui-input" readonly value="" name="isValue" id="gIntervalTime"/></td>
				<td><input class="layui-input" readonly value="" name="isCheckNum"/></td>
				<td><input class="layui-input" value="" name="isBetterNum"/></td>
				<td>
					<div class="layui-input-block" style="width: 100%;margin-left: auto">
						<select name="isDecide" class="layui-select">
							<option value="合格">合格</option>
							<option value="不合格">不合格</option>
						</select>
					</div>
				</td>
			</tr>
		</tbody>
	</table>
	<button  lay-submit id="subBtn" class="layui-btn layui-btn-blue" lay-filter="addform">提交</button>
	<button type="reset" id="addReset" class="layui-btn layui-btn-primary layui-hide" >重置</button>
</form>
<script src="${pageContext.request.contextPath }/assets/layui.js" charset="utf-8"></script>
<script src="${pageContext.request.contextPath }/assets/layui.all.js"></script>
<script src="${pageContext.request.contextPath }/assets/js/toastr.min.js" charset="utf-8"></script>
<script type="text/javascript">
//排产单输入框改变
function onInput(){
	var remark02 = $("#remark02").val();
	$.ajax({
		type:'post'
		,url:'${pageContext.request.contextPath}/inspectionSheet/selectRemark03Byremark02.do'
		,data:{'remark02':remark02}
		,dataType:'json'
		,success:function(res){
			$("#remark03").find("option").not(":first").remove();
			var length= res.data.length;
			for(var i = 0;i < length;i++){
				$("#remark03").append(
					'<option value="'+res.data[i].remark03+'">'+res.data[i].remark03+'</option>'
				)
			}
			layui.use('form', function(){  //此段代码必不可少
                var form = layui.form;
                form.render();
            });
		}
	})
	
}
//日期格式转换
function createTime(v){
	var date = new Date(v);
    var y = date.getFullYear();
    var M = date.getMonth()+1;
    M = M<10?'0'+M:M;
    var d = date.getDate();
    d = d<10?("0"+d):d;
    var h = date.getHours();
    h = h<10?("0"+h):h;
    var m = date.getMinutes();
    m = m<10?("0"+m):m;
    var str = y+"-"+M+"-"+d;
    return str;
}
//日期格式转换
function date2String(timestamp){
	var d = new Date(timestamp);
	var date = (d.getFullYear()) + "-" + 
       (d.getMonth() + 1<10?"0"+(d.getMonth() + 1):d.getMonth() + 1) + "-" +
       (d.getDate()<10?"0"+d.getDate():d.getDate()) + " " + 
       (d.getHours()<10?"0"+d.getHours():d.getHours()) + ":" + 
       (d.getMinutes()<10?"0"+d.getMinutes():d.getMinutes()) + ":" + 
       (d.getSeconds()<10?"0"+d.getSeconds():d.getSeconds());
       
       return date;
}
layui.use(['table','layer','upload','form'], function(){
	var table = layui.table;
	var layer = layui.layer,
    form = layui.form;
	
	var $ = layui.jquery, active = {
			reload:function () {
				var keyword = $("#keyword").val();
				table.reload('contenttable',{
					method:'get',
					where:{keyword:keyword}
					,page: {
						curr: 1 //重新从第 1 页开始
					}
				});
			}
		}
	$('.layui-btn').on('click', function(){
        var type = $(this).data('type');
        active[type] ? active[type].call(this) : '';
    });
	table.render({
	    elem: '#inspectionSheet'
	    ,url:'${pageContext.request.contextPath }/inspectionSheet/selectInspectionSheetList.do'
	    ,toolbar: '#toolbarDemo'
	    ,title: '产品检验单'
	    ,id :'contenttable'
	    ,limits:[10,20,30]
	    ,cols: [[
		  {type: 'checkbox', fixed: 'left',width:50}
		  ,{field:'', title:'序号', sort: true, type:'numbers', width: 60}
	      ,{field:'isNumber', title:'检验单号'}
	      ,{field:'isPerson', title:'检验人'}
	      ,{field:'isDate', title:'检验日期',templet:function(row){
	    	  return createTime(row.isDate.time);
	      }}
	      ,{fixed: 'right', title:'操作', toolbar: '#barDemo',width:150}
	    ]]
	    ,page: true
	});
  
	//头工具栏事件
	table.on('toolbar(inspectionSheet)', function(obj){
		var checkStatus = table.checkStatus(obj.config.id);
	    switch(obj.event){
	    	case 'add':
	    		layer.open({
					  type: 1 		//Page层类型
					  ,area: ['95%', '600px'] //宽  高
					  ,title: '新增'
					  ,shade: 0.1 	//遮罩透明度
					  ,maxmin: true //允许全屏最小化
					  ,anim: 1 		//0-6的动画形式，-1不开启
					  ,content: $("#content")
					  ,success:function(layero, index){
						  form.render();
					  }
	    			  ,end: function () {
	    	              $("#content").css("display","none");
	    	              $("#addReset").click();
	    	          }
				});
	      	break;
	    	case 'delete':
	        	var data = checkStatus.data;
	        	if(data.length==0){
	        		toastr.warning("请至少选择一条记录！");
	        	}
	        	var isNumberArr = new Array();
	        	for(var i=0;i<data.length;i++){
	        		isNumberArr[i] = data[i].isNumber;
	    		    layer.confirm('确定删除吗？', function(index){
	    			    $.ajax({
	    			    	type:'post',
	    			    	url:'${pageContext.request.contextPath }/inspectionSheet/delInspectionSheetArr.do',
	    			    	data:{"isNumberArr":isNumberArr},
	    			    	success:function(num){
	    			    		if(num>0){
	    			    			toastr.success("删除了"+num+"条数据！");
	    			    			setTimeout(function(){  //使用  setTimeout（）方法设定定时2000毫秒
	    								//关闭模态框
	    								// 父页面刷新
	    								window.location.reload();  
	    							},2000);
	    			    		}else{
	    			    			toastr.warning("删除失败！");
	    			    		}
	    			    	}
	    			    		
	    			    })
	    			    layer.close(index);
	    			  });
	        	}
	      	break;
	    };
	});
  
	//监听行工具事件
	table.on('tool(inspectionSheet)', function(obj){
		var data = obj.data;
		if(obj.event === 'del'){
		  layer.confirm('确定删除吗？', function(index){
			var isNumberArr = new Array();
		    var isNumber = data.isNumber;
		    isNumberArr[0] = isNumber;
		    $.ajax({
		    	type:'post',
		    	url:'${pageContext.request.contextPath }/inspectionSheet/delInspectionSheetArr.do',
		    	data:{"isNumberArr":isNumberArr},
		    	success:function(data){
		    		if(data>0){
		    			toastr.success("删除成功！");
		    			setTimeout(function(){  //使用  setTimeout（）方法设定定时2000毫秒
							//关闭模态框
							// 父页面刷新
							window.location.reload();  
						},2000);
		    		}else{
		    			toastr.warning("删除失败！");
		    		}
		    	}
		    		
		    })
		    layer.close(index);
		  });
		}
	});
	
	//监听行单击事件(子表)
	 table.on('row(inspectionSheet)', function(obj){
		var isNumber = obj.data.isNumber;
	  	table.render({
		    elem: '#inspectionSheetDetails'
		    ,url:'${pageContext.request.contextPath }/inspectionSheet/selectInspectionSheetDetailsListByNumber.do'
		    ,where:{ptNumber: isNumber}
		    ,toolbar: '#toolbarDemoDetails'
		    ,title: '产品检验详情单'
		    ,limits:[10,20,30]
		    ,cols: [[
		    	{field:'isNumber', title:'检验单号' }
			     ,{field:'isItem', title:'检验项'}
			     ,{field:'isValue', title:'检测值'}
			     ,{field:'isCheckNum', title:'检测个数'}
			     ,{field:'isBetterNum', title:'合格个数'}
			     ,{field:'isDecide', title:'判定'}
		    ]]
		    ,page: true
		});
	});
    /**
     * 通用表单提交(AJAX方式)（新增）
     */
    form.on('submit(addform)', function (data) {
    	$("#subBtn").attr("disabled",true);
    	var remark02 = $("#remark02").val();
    	var remark03 = $("#remark03").val();
    	if(remark02=='' || remark03== -1){
    		toastr.warning('请填写排产单号和检验结果！');
    		$("#subBtn").attr("disabled",false);
    	}else{
	    	$.ajax({
				type : "post",
				url : '${pageContext.request.contextPath}/inspectionSheet/insertInspectionSheet.do',
				data : $("#content").serialize(),
				cache : false,
				async:false
				}).done(
					function(res) {
						if (res == 1) {
							toastr.success('新增成功！');
						}
						setTimeout(function(){  //使用  setTimeout（）方法设定定时2000毫秒
							//关闭模态框
							// 父页面刷新
							window.location.reload();  
						},2000);
					}
				).fail(
					function(res) {
						toastr.error('新增失败！');
					}
				)
    	}
		return false;
    });
    form.on('select(remark03)', function(data){
    	//console.log(data.elem); //得到select原始DOM对象
    	//console.log(data.value); //得到被选中的值
    	//console.log(data.othis); //得到美化后的DOM对象
    	var remark02 = $("#remark02").val();
    	var remark03 = $("#remark03").val();
    	$.ajax({
    		type:'post'
    		,url:'${pageContext.request.contextPath}/inspectionSheet/selectProductTestValue.do'
    		,data:{'remark02':remark02,'remark03':remark03}
    		,dataType:'json'
    		,success:function(res){
    			//console.log(res)
    			$("#cstl").val(res.cstl);
    			$("#bsNum").val(res.bsNum);
    			$("#ryjNumCount").val(res.ryjNumCount);
    			$("#wqysNum").val(res.wqysNum);
    			$("#dmbj").val(res.dmbj);
    			$("#nleakHuntingCount").val(res.nleakHuntingCount);
    			$("#gIntervalTime").val(res.gIntervalTime);
    			var els =document.getElementsByName("isCheckNum");
    			for(var x = 0;x<els.length;x++){
    				els[x].value=res.count;
    			}
    		}
    	})
    });
});
toastr.options.positionClass = 'toast-top-center'; //提示框的位置设置为中上
</script>
</body>
</html>